package org.wlw.web.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertiesUtils {
    private final static Map<String, Properties> maps = new HashMap<>();

    public static Properties getProperties(String fname) {
        if(maps.containsKey(fname)) {
            return maps.get(fname);
        }

        InputStream is = null;
        try {
            Properties prop = new Properties();
//            System.out.println("-----------------------"+fname);
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream(fname+".properties");
            prop.load(is);
            maps.put(fname,prop);
            return prop;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(is!=null) is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }
}
